<?php
{
/**
* Initial script for testing database connection and ceating a geofence.
*/

include "makeFence.php";
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');

$json = file_get_contents('php://input');
$data = json_decode($json);
//echo $data['X']." \n";
//echo $data;
$xU = $data->X;
$yU = $data->Y;
$bearing = $data->Bearing;
$angle = 45 + $bearing;
//echo $angle;

if($angle >= 360)
{
$angle -= 360;
}
$myfence = makefence($xU, $yU, $angle);

$foundLocs = count($myfence);
$locs = count($foundLocs[0]);
$arr = array();
for($i = 0; $i < $foundLocs; $i++){
	array_push($arr, array("Name" =>$myfence[$i][0], "Latlng" =>$myfence[$i][1].", ".$myfence[$i][2]));
	//echo "Found location ".$myfence[$i][0]." at ".$myfence[$i][1].", ".$myfence[$i][2]."\n";
	}



//$user = array($xU, $yU);
//$coords = array($xA, $yA, $xB, $yB);
//$response["success"] = "yeah";
//$response["message"] = "User: ".$xU." ".$yU. ",A: ".$xA." ".$yA. ",B: ".$xB." ".$yB;
mysql_close($dbhandle);
echo json_encode($arr);
//echo nl2br("User: ".$xU." ".$yU. "\n,A: ".$xA." ".$yA. "\n,B: ".$xB." ".$yB);
//$posLocsLen = count($posLocs);
//echo $posLocsLen;
 
}

?>
	